namespace SolidMvvm {
	using System;
	using System.Globalization;
	using System.Windows.Data;

	/// <summary>
	///     This converter will convert long strings to shorter ones with ellipses examples: 1. "isilPart 1234" with max length
	///     parameter set to 10 : "isilPart..." 2. "isilPart 1" with max length parameter set to 10 : "isilPart 1"
	/// </summary>
	[ValueConversion(typeof(string), typeof(string))]
	public class StringToTruncatedStringWithEllipsesConverter : IValueConverter {
		public object Convert(object value, Type targetType, object parameter, CultureInfo culture) {
			if (parameter == null)
				throw new ArgumentOutOfRangeException("StringToTruncatedStringWithEllipsesConverter must specify a max string length parameter.");

			if (value == null)
				return null; // assume a fallback value in the caller will handle this

			if (!(value is string))
				throw new ArgumentOutOfRangeException("DoubleToMultipliedDoubleConverter must be given a string value.");

			if (!(parameter is int) && !(parameter is string))
				throw new ArgumentOutOfRangeException("DoubleToMultipliedDoubleConverter must be given a string or int parameter .");

			var intParameter = parameter is int ? (int)parameter : int.Parse((string)parameter);
			var stringValue = (string)value;

			if (stringValue.Length > intParameter)
				return stringValue.Substring(0, intParameter - 3) + "...";
			return value;
		}

		public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) {
			throw new NotImplementedException();
		}
	}
}
